package com.lcx.util;

import java.net.URL;
import java.net.URLClassLoader;

public class ClassLoaderUtil {

    public static Class<?> loadClass(String []jarFiles,String className) throws Exception{
        URL urls[] = new URL[jarFiles.length];
         for(int i=0;i<jarFiles.length;i++){
             urls[i] = new URL("file:///"+jarFiles[i]);
         }
        ClassLoader classLoader = new URLClassLoader(urls);
        Thread.currentThread().setContextClassLoader(classLoader);
        return classLoader.loadClass(className);
    }

    public static Class<?> loadClassFromCurrentThread(String className) throws Exception{
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if(classLoader!=null){
            return classLoader.loadClass(className);
        }
        return null;
    }

}
